﻿<UserControl x:Class="Samba.Modules.MenuModule.TicketTagGroupView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:PropertyEditorLibrary="clr-namespace:PropertyTools.Wpf;assembly=PropertyTools.Wpf"
     mc:Ignorable="d">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <StackPanel Grid.Row="0">
            <Label>
                <LocText ResourceIdentifierKey="TicketTagName" Suffix=":" />
            </Label>
            <TextBox HorizontalAlignment="Left" MinWidth="200" Text="{Binding Name,Mode=TwoWay}" />
            <Label>
                <LocText ResourceIdentifierKey="Numerator" Suffix=":" />
            </Label>
            <ComboBox HorizontalAlignment="Left" MinWidth="150" IsEditable="True" SelectedItem="{Binding Numerator}"
                 ItemsSource="{Binding Numerators}" DisplayMemberPath="Name" />
            <Label>
                <LocText ResourceIdentifierKey="DoAfterTicketSelected" Suffix=":" />
            </Label>
            <ComboBox HorizontalAlignment="Left" MinWidth="150" SelectedItem="{Binding Action}"
                 ItemsSource="{Binding Actions}" />
            <CheckBox Margin="0,10,0,1" IsChecked="{Binding ActiveOnPosClient}">
                <LocText ResourceIdentifierKey="CanUseOnPOS" />
            </CheckBox>
            <CheckBox Margin="0,1" IsChecked="{Binding ActiveOnTerminalClient}">
                <LocText ResourceIdentifierKey="CanUseOnTerminal" />
            </CheckBox>
            <CheckBox Margin="0,1" IsChecked="{Binding ForceValue}">
                <LocText ResourceIdentifierKey="SelectionRequired" />
            </CheckBox>
            <CheckBox Margin="0,1" IsChecked="{Binding ExcludeInReports}">
                <LocText ResourceIdentifierKey="HideItOnReports" />
            </CheckBox>
            <CheckBox Margin="0,1" IsChecked="{Binding FreeTagging}">
                <LocText ResourceIdentifierKey="FreeTagging" />
            </CheckBox>
            <CheckBox Margin="0,1" IsChecked="{Binding SaveFreeTags}">
                <LocText ResourceIdentifierKey="SaveFreeTags" />
            </CheckBox>
            <Label>
                <LocText ResourceIdentifierKey="TagType"/>
            </Label>
            <ComboBox Margin="0,1,0,5" HorizontalAlignment="Left" MinWidth="150" SelectedItem="{Binding TaggingType}"
                 ItemsSource="{Binding TagTypes}" />
            <GroupBox Header="{LocText ButtonColors}" Padding="5" HorizontalAlignment="Left">
                <StackPanel>
                    <Label>
                        <LocText ResourceIdentifierKey="WhenTagSelected" Suffix=":" />
                    </Label>
                    <PropertyEditorLibrary:ColorPicker HorizontalAlignment="Left" MinWidth="150" SelectedColor="{Binding ButtonColorWhenTagSelected}" />
                    <Label>
                        <LocText ResourceIdentifierKey="WhenTagNotSelected" Suffix=":" />
                    </Label>
                    <PropertyEditorLibrary:ColorPicker HorizontalAlignment="Left" MinWidth="150" SelectedColor="{Binding ButtonColorWhenNoTagSelected}" />
                </StackPanel>
            </GroupBox>
        </StackPanel>
        <GroupBox Margin="10,0" Grid.Row="0" Grid.Column="1" Padding="5" Header="{LocText SubTags}">
            <StackPanel Orientation="Horizontal">
                <DataGrid ItemsSource="{Binding TicketTags}" SelectedItem="{Binding SelectedTicketTag, Mode=TwoWay}"
                     HorizontalAlignment="Left" GridLinesVisibility="None" RowHeaderWidth="0" Margin="0,3"
                     AutoGenerateColumns="False" CanUserSortColumns="False" Background="{StaticResource {x:Static SystemColors.WindowBrushKey}}"
                     CellEditEnding="DataGrid_CellEditEnding">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="{LocText TagName}" MinWidth="100" Binding="{Binding Name}" />
                        <DataGridTemplateColumn Header="{LocText Account}" MinWidth="100">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Margin="3" Text="{Binding AccountName}" />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                            <DataGridTemplateColumn.CellEditingTemplate>
                                <DataTemplate>
                                    <Grid FocusManager.FocusedElement="{Binding ElementName=cb}">
                                        <ComboBox Name="cb" IsEditable="True" ItemsSource="{Binding AccountNames}" SelectedItem="{Binding AccountName}" />
                                    </Grid>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellEditingTemplate>
                        </DataGridTemplateColumn>
                    </DataGrid.Columns>
                    <DataGrid.ContextMenu>
                        <ContextMenu>
                            <MenuItem Command="{Binding AddTicketTagCommand}" Header="{Binding AddTicketTagCommand.Caption}" />
                            <MenuItem Command="{Binding DeleteTicketTagCommand}" Header="{Binding DeleteTicketTagCommand.Caption}" />
                        </ContextMenu>
                    </DataGrid.ContextMenu>
                </DataGrid>
                <StackPanel Margin="10">
                    <TextBlock Margin="2,3">
                        <Hyperlink Command="{Binding AddTicketTagCommand}">
                            <TextBlock Text="{Binding Path=AddTicketTagCommand.Caption}" />
                        </Hyperlink>
                    </TextBlock>
                    <TextBlock Margin="2,3">
                        <Hyperlink Command="{Binding DeleteTicketTagCommand}">
                            <TextBlock Text="{Binding Path=DeleteTicketTagCommand.Caption}" />
                        </Hyperlink>
                    </TextBlock>
                </StackPanel>
            </StackPanel>
        </GroupBox>
        <StackPanel Grid.Row="1">
            <Button HorizontalAlignment="Left" Margin="0,10" MinWidth="70" Content="{Binding SaveCommand.Caption}"
                 Command="{Binding SaveCommand}" />
            <Label Content="{Binding Error}" Foreground="Red" />
        </StackPanel>
    </Grid>
</UserControl>